package com.tanhua.dubbo.api;

import com.tanhua.model.mongo.Proclamation;
import org.apache.dubbo.config.annotation.DubboService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@DubboService
public class ProclamationApiImpl implements ProclamationApi {

    @Autowired
    private MongoTemplate mongoTemplate;


    @Override
    public List<Proclamation> selectPage(Integer page, Integer pagesize) {
        Criteria criteria = new Criteria();
        Query query = new Query(criteria);
        query.skip((page-1)*pagesize).limit(pagesize).with(Sort.by(Sort.Order.desc("created")));
        List<Proclamation> list = mongoTemplate.find(query, Proclamation.class);

        return list;
    }

    @Override
    public Long getcount() {
        long count = mongoTemplate.count(new Query(new Criteria()), Proclamation.class);
        return count;
    }
}
